/*
 * @Author: wangdengduo
 * @Date: 2023-05-08 17:13:51
 * @LastEditors: wangdengduo
 * @LastEditTime: 2023-05-09 18:12:31
 * @FilePath: \todo-list\src\store\index.js
 * @Description:
 */
import { createContext, useReducer } from "react";

export const searchContext = createContext({
  searchValue: "",
  dispatch: () => {},
  theme: "light",
  dispatchTheme: () => {},
});

export const Store = (props) => {
  const [searchValue, dispatch] = useReducer((state, action) => {
    switch (action.type) {
      case "UPDATE":
        return action.value;
      default:
        return state;
    }
  }, []);

  const [theme, dispatchTheme] = useReducer((state, action) => {
    switch (action.type) {
      case "UPDATE":
        return action.value;
      default:
        return state;
    }
  }, []);

  return (
    <searchContext.Provider
      value={{ searchValue, dispatch, theme, dispatchTheme }}
    >
      {props.children}
    </searchContext.Provider>
  );
};
